package cn.ha.toy.entity;

import java.util.List;
import java.util.Set;

import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;

public class QueryFilter extends LinkedMultiValueMap<String,String>{
	/**
	 * 
	 */
	private static final long serialVersionUID = -4748582257990668819L;

	public void show(){
		Set<String> keys = this.keySet();
		for(String key : keys ){
			System.out.println(key+"  "+this.get("key"));
		}
	}
	
	public QueryFilter( int size ){
		super(size);
	}
	
	public MultiValueMap<String, String> filter(String prefix){
		MultiValueMap<String, String> result = new LinkedMultiValueMap<String, String>();
		Set<String> keys = this.keySet();
		for( String key : keys){
			if( !StringUtils.isEmpty(key) && key.startsWith(prefix) ){
				List<String> values = get(key);
				if( values!=null && values.size()>0 ){
					for(String value : values){
						result.add(key, value);
					}
				}
			}
		}
		return result;
	}
}
